﻿using System;
using System.Collections.Generic;
using System.Web.UI;

namespace HelfenHelfen.Web.Forms.Site.Utility {
   public static class Utility {
      /// <summary> 
      /// Finds a Control recursively. Note finds the first match that exists 
      /// </summary> 
      /// <param name="ContainerCtl">Should be the lowest container in the heirarchy, for eg dont choose Master page if you can pick the specific panel</param> 
      /// <param name="IdToFind">ID of the control you are looking for</param> 
      /// <returns>the control if found else null</returns> 
      /// see: http://forums.asp.net/t/1107107.aspx
      public static Control FindControlRecursive(this Control Root, string Id) {
         if (Root.ID == Id)
            return Root;

         foreach (Control Ctl in Root.Controls) {
            Control FoundCtl = Ctl.FindControlRecursive(Id);
            if (FoundCtl != null)
               return FoundCtl;
         }

         return null;
      }
   }
}